<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.创建该对象
        let xml = new XMLHttpRequest();
        //2.打开/创建一个链接
        xml.open("GET", "http://localhost:8080/api/get", true);
        //3.发送请求
        xml.send();
        //4.设置回应事件
        xml.onreadystatechange = function () {
            if (xml.readyState == 4 && xml.status == 200) {
                //传过来的时json对象，得转成js对象处理
                let jsontest = xml.responseText;
                let jsonobj = JSON.parse(jsontest);
                console.log(jsonobj);
            }
        }

    </script>
</body>

</html>